package com.ssy.lingxi.product.entity.material;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.Goods;
import com.ssy.lingxi.product.entity.commodity.Commodity;
import com.ssy.lingxi.product.entity.customer.CustomerAttribute;
import com.ssy.lingxi.product.entity.customer.CustomerAttributeValue;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * 物料属性实体类
 * @author lqa
 * @version 2.0.0
 * @date 2022/3/24
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_material_attribute")
public class MaterialAttribute {

    private static final long serialVersionUID = -8259447164769132869L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="material_attribute_seq")
    @SequenceGenerator(sequenceName="product_material_attribute_seq", name="material_attribute_seq",allocationSize = 1)
    private Long id;

    /**
     * 物料id（货品id）
     */
    @JsonIgnore
    @ManyToOne(cascade={CascadeType.PERSIST})
    @JoinColumn(name="goodsId",referencedColumnName = "id")
    private Goods goods;

    /**
     * 会员属性
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="customerAttributeId",referencedColumnName = "id")
    private CustomerAttribute customerAttribute;

    /**
     * 会员属性值
     */
    @JsonManagedReference
    @ManyToMany(cascade={CascadeType.PERSIST, CascadeType.DETACH})
    @JoinTable(name="product_material_attribute_value",
            joinColumns={ @JoinColumn(name="material_attribute_id", referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="customer_attribute_value_id", referencedColumnName="id")})
    private List<CustomerAttributeValue> customerAttributeValueList;
}
